package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo9 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("欢迎来到用户登录");
        System.out.print("请输入用户名:");
        String name = scan.next();
        System.out.print("请输入密码:");
        String pwd = scan.next();

        try (Connection conn = DBUtil.getConnection();){
            String sql = "SELECT username,password,nickname,age " +
                    "FROM userinfo " +
                    "WHERE username = ? AND password = ?";
            PreparedStatement st = conn.prepareStatement(sql);
            st.setString(1,name);
            st.setString(2,pwd);
            ResultSet rs = st.executeQuery();
            System.out.println(rs.next() ? "登录成功" : "登录失败");


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
